from app.models import SQLBaseModel
from sqlmodel import Field, Relationship, SQLModel
from typing import TYPE_CHECKING, List, Optional

if TYPE_CHECKING:
    from .dict import Dict


class BaseDictType(SQLModel):
    name: str = Field(nullable=False, index=True, description="名称")
    code: str = Field(nullable=False, index=True, description="编码")
    description: Optional[str] = Field(default=None, description="描述")

    sort: int = Field(default=100, index=True, description="顺序")
    is_enabled: bool = Field(default=True, index=True, description="是否启用")


class DictType(SQLBaseModel, BaseDictType, table=True):
    __tablename__ = "dict_type"

    """一对多关系"""
    dicts: List["Dict"] = Relationship(back_populates="dict_type")
